<!-- src/components/StatisticCard.vue -->
<template>
  <div class="statistic-card">
    <div class="header">
      <el-icon :color="color" class="icon">
        <component :is="icon" />
      </el-icon>
      <span class="title">{{ title }}</span>
    </div>
    <div class="content">
      <span class="value" :style="{ color }">{{ formattedValue }}</span>
    </div>
  </div>
</template>

<script setup lang="ts">
import {Component, computed} from 'vue'

const props = defineProps({
  title: {
    type: String,
    required: true
  },
  value: {
    type: [Number, String],
    required: true
  },
  icon: {
    type: Object as () => Component,
    required: true
  },
  color: {
    type: String,
    default: '#409EFF'
  },
  precision: {
    type: Number,
    default: 0
  }
})

const formattedValue = computed(() => {
  if (typeof props.value === 'number') {
    return props.value.toFixed(props.precision)
  }
  return props.value
})
</script>

<style scoped>
.statistic-card {
  padding: 16px;
  background: white;
  border-radius: 4px;
}

.header {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
}

.icon {
  font-size: 24px;
  margin-right: 8px;
}

.title {
  font-size: 14px;
  color: #606266;
}

.value {
  font-size: 24px;
  font-weight: 600;
}
</style>